package com.jpro.framework.jackson.core.databind;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.OffsetDateTime;

/**
 * OffsetDateTime序列化规则
 * <p>
 * 会将OffsetDateTime序列化为毫秒级时间戳
 */
public class OffsetDateTimeSerializer extends JsonSerializer<OffsetDateTime> {

    public static final OffsetDateTimeSerializer INSTANCE = new OffsetDateTimeSerializer();

    @Override
    public void serialize(OffsetDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeNumber(value.toInstant().toEpochMilli());
    }
}
